package com.banciyuan.bcywebview.biz.circles.smooth.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.factory.TimelineFactory;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.DetailDataHelper;
import com.banciyuan.bcywebview.base.helper.timelinedatacenter.TimelineLikeHelper;
import com.banciyuan.bcywebview.base.view.tag.TagView;
import com.banciyuan.bcywebview.biz.ask.AskActivity;
import com.banciyuan.bcywebview.biz.circles.smooth.CircleSmoothActivity;
import com.banciyuan.bcywebview.biz.circles.smooth.CircleTagSmoothActivity;
import com.banciyuan.bcywebview.biz.circles.smooth.viewholder.EmptyHolder;
import com.banciyuan.bcywebview.biz.circles.smooth.viewholder.GridCircleBaseItem;
import com.banciyuan.bcywebview.biz.circles.smooth.viewholder.NewestHeaderHolder;
import com.banciyuan.bcywebview.biz.circles.smooth.viewholder.SmallGroupHolder;
import com.banciyuan.bcywebview.biz.circles.smooth.viewholder.TopUserHolder;
import com.banciyuan.bcywebview.biz.detail.goods.GoodsDetailActivity;
import com.banciyuan.bcywebview.biz.event.EventDetailActivity;
import com.banciyuan.bcywebview.biz.groupdetail.NewTeamDetailActivity;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.TimelineCardType;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.BaseView;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewArticle;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewDaily;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewGroupTeam;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewHolder;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewPost;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallDaily;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallGroup;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallLongDaily;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallMain;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallVideoDaily;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewSmallWrite;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewVideo;
import com.banciyuan.bcywebview.biz.main.mainpage.timeline.viewholder.ViewWriter;
import com.banciyuan.bcywebview.biz.pc.zone.smooth.SmoothPersonActivity;
import com.banciyuan.bcywebview.biz.write.photoselecotor.util.CommonUtils;
import com.banciyuan.bcywebview.utils.common.UIUtils;
import com.banciyuan.bcywebview.utils.http.VolleyQueue;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.string.StringUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import java.util.ArrayList;
import java.util.List;

import de.greenrobot.daoexample.model.TagDetail;
import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by squall on 2016/6/24.
 */
public class CircleSmoothTimelineAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<Timeline> clist = new ArrayList<>();
    private List<Timeline> tlist = new ArrayList<>();

    private NewestHeaderHolder newestHeaderHolder;

    private RequestQueue mQueue;

    private int height;
    private int max = -1;
    private int min_height;
    private boolean loading;
    private boolean isAnimation_runing;

    public CircleSmoothTimelineAdapter(Context context, List<Timeline> clist, List<Timeline> tlist, NewestHeaderHolder newestHeaderHolder, boolean loading) {
        this.newestHeaderHolder = newestHeaderHolder;
        this.mContext = context;
        this.clist = clist;
        this.tlist = tlist;
        this.loading = loading;
        mQueue = VolleyQueue.getRquest(mContext);
        min_height = CommonUtils.getHeightPixels((Activity) mContext) - CommonUtils.getStatusPixels((Activity) mContext) - UIUtils.dip2px(94, mContext);
    }

    @Override
    public int getItemViewType(int position) {
        if (tlist.isEmpty()) {
            if (position == 0) {
                return TimelineCardType.BLANK_HEADER;
            } else if (position == 1) {
                return TimelineCardType.FILTER_CARD;
            } else if (position == getItemCount() - 1) {
                return TimelineCardType.BLANK_BOTTOM;
            } else {
                Timeline mItem = clist.get(position - 2);
                switch (TimelineFactory.whichType(mItem)) {
                    case TimelineFactory.TIMELINE_TYPE_ILLUST:
                    case TimelineFactory.TIMELINE_TYPE_COSER:
                    default:
                        return TimelineCardType.COSILL_CARD;
                    case TimelineFactory.TIMELINE_TYPE_DAILY:
                        if (StringUtil.notNullEqual(mItem.getType(), "larticle")) {
                            return TimelineCardType.ARTICLE_CARD;
                        } else if (StringUtil.notNullEqual(mItem.getType(), "svideo")) {
                            return TimelineCardType.VIDEO_CARD;
                        } else {
                            return TimelineCardType.DAILY_CARD;
                        }
                    case TimelineFactory.TIMELINE_TYPE_WRITER:
                        return TimelineCardType.WRITER_CARD;
                    case TimelineFactory.TIMELINE_TYPE_GROUP_TEAM:
                        return TimelineCardType.GROUP_CARD;
                    case TimelineFactory.TIMELINE_TYPE_GROUP:
                        return TimelineCardType.GROUP_POST_CARD;
                    case TimelineFactory.TIMELINE_TYPE_EMPTY:
                        return TimelineCardType.EMPTY_CARD;
                    case TimelineFactory.TIMELINE_TYPE_LOCAL:
                        if (mItem.getPost_rank() != null) {
                            return TimelineCardType.USER_CARD;
                        } else {
                            return TimelineCardType.HEARDER_CARD;
                        }
                }
            }
        } else {
            if (position == 0) {
                return TimelineCardType.BLANK_HEADER;
            } else if (position == 1) {
                return TimelineCardType.FILTER_CARD;
            } else if (position == getItemCount() - 1) {
                return TimelineCardType.BLANK_BOTTOM;
            } else {
                Timeline mItem = tlist.get(position - 2);
                switch (TimelineFactory.whichType(mItem)) {
                    case TimelineFactory.TIMELINE_TYPE_EMPTY:
                        return TimelineCardType.EMPTY_CARD;
                    case TimelineFactory.TIMELINE_TYPE_GROUP_TEAM:
                        return TimelineCardType.SMALL_CARD_GROUP;
                    case TimelineFactory.TIMELINE_TYPE_COSER:
                    case TimelineFactory.TIMELINE_TYPE_ILLUST:
                    default:
                        return TimelineCardType.SMALL_MAIN_CARD;
                    case TimelineFactory.TIMELINE_TYPE_DAILY:
                        if ("larticle".equals(mItem.getType())) {
                            return TimelineCardType.SMALL_LONGDAILY_CARD;
                        } else if ("svideo".equals(mItem.getType())) {
                            return TimelineCardType.SMALL_VIDEO_CARD;
                        } else {
                            return TimelineCardType.SMALL_DAILY_CARD;
                        }
                    case TimelineFactory.TIMELINE_TYPE_GROUP:
                        return TimelineCardType.SMALL_GROUPPOST_CARD;
                    case TimelineFactory.TIMELINE_TYPE_WRITER:
                        return TimelineCardType.SMALL_WRITE_CARD;
                }
            }
        }
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TimelineCardType.COSILL_CARD:
            default:
                return new ViewHolder(View.inflate(mContext, R.layout.ground_list_item, null));
            case TimelineCardType.DAILY_CARD:
                return new ViewDaily(View.inflate(mContext, R.layout.new_daily_list_item, null));
            case TimelineCardType.WRITER_CARD:
                return new ViewWriter(View.inflate(mContext, R.layout.timeline_writer_list_item, null));
            case TimelineCardType.GROUP_CARD:
                return new ViewGroupTeam(View.inflate(mContext, R.layout.timeline_groupteam_item, null));
            case TimelineCardType.GROUP_POST_CARD:
                return new ViewPost(View.inflate(mContext, R.layout.new_post_list_item, null));
            case TimelineCardType.BLANK_HEADER:
                return new BlankHolder(View.inflate(mContext, R.layout.smooth_blank, null));
            case TimelineCardType.BLANK_BOTTOM:
                return new BottomHolder(View.inflate(mContext, R.layout.circle_index_smooth_bottom, null));
            case TimelineCardType.ARTICLE_CARD:
                return new ViewArticle(View.inflate(mContext, R.layout.timeline_article_item, null));
            case TimelineCardType.FILTER_CARD:
                return newestHeaderHolder;
            case TimelineCardType.USER_CARD:
                return new TopUserHolder(View.inflate(mContext, R.layout.circle_user_item, null));
            case TimelineCardType.EMPTY_CARD:
                return new EmptyHolder(View.inflate(mContext, R.layout.circle_content_empty, null));
            case TimelineCardType.SMALL_CARD_GROUP:
                return new SmallGroupHolder(View.inflate(mContext, R.layout.circle_pinterest_group_item, null));
            case TimelineCardType.VIDEO_CARD:
                return new ViewVideo(View.inflate(mContext, R.layout.timeline_video_item, null));
            case TimelineCardType.SMALL_MAIN_CARD:
                return new ViewSmallMain(View.inflate(mContext, R.layout.circle_grid_cos_item, null));
            case TimelineCardType.SMALL_DAILY_CARD:
                return new ViewSmallDaily(View.inflate(mContext, R.layout.circle_grid_daily_item, null));
            case TimelineCardType.SMALL_WRITE_CARD:
                return new ViewSmallWrite(View.inflate(mContext, R.layout.circle_grid_write_item, null));
            case TimelineCardType.SMALL_GROUPPOST_CARD:
                return new ViewSmallGroup(View.inflate(mContext, R.layout.circle_grid_group_item, null));
            case TimelineCardType.SMALL_LONGDAILY_CARD:
                return new ViewSmallLongDaily(View.inflate(mContext, R.layout.circle_grid_longdaily_item, null));
            case TimelineCardType.SMALL_VIDEO_CARD:
                return new ViewSmallVideoDaily(View.inflate(mContext, R.layout.circle_grid_video_item, null));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (position == 0) {
            setHeaderBlankHolder((BlankHolder) holder);
        } else if (position == 1) {
            setHeight(holder, position);
        } else if (position == getItemCount() - 1) {
            setFooterBlankHolder((BottomHolder) holder);
        } else {
            if (tlist.isEmpty()) {
                Timeline mItem = clist.get(position - 2);
                switch (getItemViewType(position)) {
                    case TimelineCardType.COSILL_CARD:
                    default:
                        ViewHolder viewHolder = (ViewHolder) holder;
                        setCosIll(viewHolder, mItem, position);
                        setHeight(viewHolder, position);
                        break;
                    case TimelineCardType.DAILY_CARD:
                        ViewDaily viewDaily = (ViewDaily) holder;
                        setDaily(viewDaily, mItem, position);
                        setHeight(viewDaily, position);
                        break;
                    case TimelineCardType.WRITER_CARD:
                        ViewWriter viewWriter = (ViewWriter) holder;
                        setWriter(viewWriter, mItem, position);
                        setHeight(viewWriter, position);
                        break;
                    case TimelineCardType.GROUP_CARD:
                        ViewGroupTeam viewGroupTeam = (ViewGroupTeam) holder;
                        setGroup(viewGroupTeam, mItem, position);
                        setHeight(viewGroupTeam, position);
                        break;
                    case TimelineCardType.USER_CARD:
                        TopUserHolder userHolder = (TopUserHolder) holder;
                        userHolder.renderUser(mContext, mItem);
                        setHeight(userHolder, position);
                        break;
                    case TimelineCardType.GROUP_POST_CARD:
                        ViewPost viewPost = (ViewPost) holder;
                        setPost(viewPost, mItem, position);
                        setHeight(viewPost, position);
                        break;
                    case TimelineCardType.ARTICLE_CARD:
                        ViewArticle viewArticle = (ViewArticle) holder;
                        setArticle(viewArticle, mItem, position);
                        setHeight(viewArticle, position);
                        break;
                    case TimelineCardType.EMPTY_CARD:
                        EmptyHolder emptyHolder = (EmptyHolder) holder;
                        setEmptyHolder(emptyHolder);
                        setHeight(emptyHolder, position);
                        break;
                    case TimelineCardType.VIDEO_CARD:
                        ViewVideo viewVideo = (ViewVideo) holder;
                        setVideo(viewVideo, mItem, position);
                        setHeight(viewVideo, position);
                        break;
                }
            } else {
                Timeline item = tlist.get(position - 2);
                switch (getItemViewType(position)) {
                    case TimelineCardType.EMPTY_CARD:
                        EmptyHolder emptyHolder = (EmptyHolder) holder;
                        setEmptyHolder(emptyHolder);
                        setHeightMulti(emptyHolder, position);
                        break;
                    case TimelineCardType.SMALL_CARD_GROUP:
                        SmallGroupHolder smallGroupHolder = (SmallGroupHolder) holder;
                        smallGroupHolder.renderGroup(mContext, item);
                        setHeightMulti(smallGroupHolder, position);
                        break;
                    case TimelineCardType.SMALL_MAIN_CARD:
                    default:
                        ViewSmallMain viewSmallMain = (ViewSmallMain) holder;
                        renderGridMain(position, viewSmallMain, item);
                        setHeightMulti(viewSmallMain, position);
                        break;
                    case TimelineCardType.SMALL_DAILY_CARD:
                        ViewSmallDaily viewSmallDaily = (ViewSmallDaily) holder;
                        renderGridDaily(position, viewSmallDaily, item);
                        setHeightMulti(viewSmallDaily, position);
                        break;
                    case TimelineCardType.SMALL_WRITE_CARD:
                        ViewSmallWrite viewSmallWrite = (ViewSmallWrite) holder;
                        renderGridWrite(position, viewSmallWrite, item);
                        setHeightMulti(viewSmallWrite, position);
                        break;
                    case TimelineCardType.SMALL_GROUPPOST_CARD:
                        ViewSmallGroup viewSmallGroup = (ViewSmallGroup) holder;
                        renderGridGroup(position, viewSmallGroup, item);
                        setHeightMulti(viewSmallGroup, position);
                        break;
                    case TimelineCardType.SMALL_LONGDAILY_CARD:
                        ViewSmallLongDaily viewSmallLongDaily = (ViewSmallLongDaily) holder;
                        renderGridLongDaily(position, viewSmallLongDaily, item);
                        setHeightMulti(viewSmallLongDaily, position);
                        break;
                    case TimelineCardType.SMALL_VIDEO_CARD:
                        ViewSmallVideoDaily viewSmallVideoDaily = (ViewSmallVideoDaily) holder;
                        renderGridVideo(position, viewSmallVideoDaily, item);
                        setHeightMulti(viewSmallVideoDaily, position);
                        break;
                }
            }
        }
    }

    private void setEmptyHolder(EmptyHolder emptyHolder) {
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.MATCH_PARENT);
        emptyHolder.itemView.setLayoutParams(layoutParams);
    }

    private void setFooterBlankHolder(BottomHolder bottomHolder) {
        int footer = min_height - height;
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, footer > 0 ? footer : 1);
        bottomHolder.blank.setLayoutParams(layoutParams);
        if (loading) {
            bottomHolder.loading.setVisibility(View.VISIBLE);
        } else {
            bottomHolder.loading.setVisibility(View.GONE);
        }
    }

    private void setHeaderBlankHolder(BlankHolder blankHolder) {
        int offset = 0;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            offset = UIUtils.dip2px(20, mContext);
        }
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIUtils.dip2px(206, mContext) + offset);
        blankHolder.blank.setLayoutParams(layoutParams);
    }

    private void setHeightMulti(RecyclerView.ViewHolder viewItem, int position) {
        if (height < min_height && position > max) {
            viewItem.itemView.measure(
                    View.MeasureSpec.makeMeasureSpec(CommonUtils.getWidthPixels((Activity) mContext) / 2, View.MeasureSpec.AT_MOST),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            boolean mod = (position - 2) % 2 == 0;
            if (mod) {
                height += viewItem.itemView.getMeasuredHeight();
            }
            max = position;
        }
    }

    private void setHeight(RecyclerView.ViewHolder baseView, int position) {
        if (height < min_height && position > max) {
            baseView.itemView.measure(
                    View.MeasureSpec.makeMeasureSpec(CommonUtils.getWidthPixels((Activity) mContext), View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            height += baseView.itemView.getMeasuredHeight();
            max = position;
        }
    }


    private void setOrgin(BaseView baseView, Timeline mItem) {
        if (StringUtil.notNullStartWithUrlHead(mItem.getOavatar()))
            ImageLoader.getInstance().displayImage(mItem.getOavatar(), baseView.head, ImageOptions.optionHead);
        else
            baseView.head.setImageDrawable(mContext.getResources().getDrawable(R.drawable.user_pic_big));
        baseView.name.setText(mItem.getUName());
        baseView.time.setText(StringUtil.getOppositeTime(mItem.getPushtime()));
    }

    private void setBottom(BaseView baseView, final Timeline mItem) {
        if (!TextUtils.isEmpty(mItem.getCommentNum()) && baseView.commentNum != null) {
            if (Integer.parseInt(mItem.getCommentNum()) > 0) {
                baseView.commentNum.setText(mItem.getCommentNum());
            } else {
                baseView.commentNum.setText(mContext.getString(R.string.comment));
            }
        }
        if (StringUtil.getHaveDingBoolean(mItem)) {
            baseView.likeNumImg.setImageResource(R.drawable.like_pink);
            baseView.likeNum.setText(mItem.getLikeNum());
        } else {
            baseView.likeNumImg.setImageResource(R.drawable.like_grey);
            baseView.likeNum.setText(mItem.getLikeNum());
            if (mItem.getLikeNum().equals("0")) {
                baseView.likeNum.setText(mContext.getString(R.string.good));
            }
        }
        if (StringUtil.notNullEqual(mItem.getHaveRecommend(), "true")) {
            baseView.recommend.setText(mContext.getString(R.string.all_recommended));
        } else {
            baseView.recommend.setText(mContext.getString(R.string.all_recommend));
        }
    }

    private void setVideo(ViewVideo mViewVideo, Timeline mItem, int position) {
        ImageLoader.getInstance().displayImage(mItem.getContentAddress(), mViewVideo.content, ImageOptions.optionsTimeline, null, null, false);
        if (!TextUtils.isEmpty(mItem.getTitle())) {
            mViewVideo.title.setVisibility(View.VISIBLE);
            mViewVideo.title.setText(Html.fromHtml(mItem.getTitle()));
        } else {
            mViewVideo.title.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getSummary())) {
            mViewVideo.intro.setVisibility(View.VISIBLE);
            mViewVideo.intro.setText(Html.fromHtml(mItem.getSummary()).toString().trim());
        } else {
            mViewVideo.intro.setVisibility(View.GONE);
        }
        try {
            String time = StringUtil.getTimeDuration((int) Double.parseDouble(mItem.getVideo_info().getDuration()));
            mViewVideo.pageNum.setText(time);
            mViewVideo.pageNum.setVisibility(View.VISIBLE);
        } catch (Exception e) {
            mViewVideo.pageNum.setVisibility(View.GONE);
        }
        setOrgin(mViewVideo, mItem);
        setBottom(mViewVideo, mItem);
        processTagData(mViewVideo, mItem, 0);
        OnClick groundOnClick = new OnClick(position);
        mViewVideo.head.setOnClickListener(groundOnClick);
        mViewVideo.title.setOnClickListener(groundOnClick);
        mViewVideo.name.setOnClickListener(groundOnClick);
        mViewVideo.recommendLayout.setOnClickListener(groundOnClick);
        mViewVideo.content.setOnClickListener(groundOnClick);
        mViewVideo.likeLayout.setOnClickListener(groundOnClick);
        mViewVideo.commentLayout.setOnClickListener(groundOnClick);
        mViewVideo.intro.setOnClickListener(groundOnClick);
    }

    private void setCosIll(ViewHolder mViewHolder, Timeline mItem, int postion) {
        ImageLoader.getInstance().displayImage(mItem.getContentAddress(), mViewHolder.content, ImageOptions.optionsTimeline, null, null, true);
        if (!TextUtils.isEmpty(mItem.getPicNum())) {
            if (Integer.parseInt(mItem.getPicNum()) > 1) {
                mViewHolder.pageNum.setVisibility(View.VISIBLE);
            } else {
                mViewHolder.pageNum.setVisibility(View.GONE);
            }
        }
        if (!TextUtils.isEmpty(mItem.getIntro())) {
            mViewHolder.intro.setVisibility(View.VISIBLE);
            mViewHolder.intro.setText(Html.fromHtml(mItem.getIntro()).toString().trim().replaceAll("(\\n)+", "\n"));
        } else {
            mViewHolder.intro.setVisibility(View.GONE);
        }
        setOrgin(mViewHolder, mItem);
        setBottom(mViewHolder, mItem);
        processTagData(mViewHolder, mItem, 0);
        OnClick groundOnClick = new OnClick(postion);
        mViewHolder.head.setOnClickListener(groundOnClick);
        mViewHolder.name.setOnClickListener(groundOnClick);
        mViewHolder.recommendLayout.setOnClickListener(groundOnClick);
        mViewHolder.content.setOnClickListener(groundOnClick);
        mViewHolder.likeLayout.setOnClickListener(groundOnClick);
        mViewHolder.commentLayout.setOnClickListener(groundOnClick);
        mViewHolder.intro.setOnClickListener(groundOnClick);

    }

    private void setDaily(ViewDaily mViewDaily, Timeline mItem, int postion) {
        if (!TextUtils.isEmpty(mItem.getContentAddress())) {
            String[] addressList = mItem.getContentAddress().split(" ");
            if (addressList.length == 0) {
                mViewDaily.imagePics.setVisibility(View.GONE);
            } else {
                mViewDaily.imagePics.setVisibility(View.VISIBLE);
                for (int i = 0; i < mViewDaily.content.length; i++) {
                    LinearLayout.LayoutParams ll = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
                    if (addressList.length == 1) {
                        ll.weight = 2 - i;
                    } else {
                        ll.weight = 1;
                        if (i < 2) {
                            ll.rightMargin = UIUtils.dip2px(4, mContext);
                        }
                    }
                    mViewDaily.content[i].setLayoutParams(ll);
                    if (i < addressList.length) {
                        mViewDaily.content[i].setVisibility(View.VISIBLE);
                        ImageLoader.getInstance().displayImage(addressList[i], mViewDaily.content[i], ImageOptions.options);
                    } else {
                        if (addressList.length == 1) {
                            mViewDaily.content[i].setVisibility(View.INVISIBLE);
                        } else {
                            mViewDaily.content[i].setVisibility(View.GONE);
                        }
                    }
                }
            }
        } else {
            mViewDaily.imagePics.setVisibility(View.GONE);
        }
        String pic_num = mItem.getPic_num();
        if (!TextUtils.isEmpty(pic_num)) {
            if (Integer.parseInt(pic_num) > 3) {
                mViewDaily.pagenum.setVisibility(View.VISIBLE);
            } else {
                mViewDaily.pagenum.setVisibility(View.GONE);
            }
        } else {
            mViewDaily.pagenum.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(mItem.getIntro())) {
            mViewDaily.intro.setVisibility(View.GONE);
        } else {
            mViewDaily.intro.setVisibility(View.VISIBLE);
            mViewDaily.intro.setText(mItem.getIntro());
        }
        setOrgin(mViewDaily, mItem);
        setBottom(mViewDaily, mItem);
        if (TimelineFactory.whichType(mItem) == TimelineFactory.TIMELINE_TYPE_DAILY) {
            processTagData(mViewDaily, mItem, 0);
        } else {
            mViewDaily.tags.setVisibility(View.GONE);
        }
        OnClick dailyOnClick = new OnClick(postion);
        mViewDaily.head.setOnClickListener(dailyOnClick);
        mViewDaily.name.setOnClickListener(dailyOnClick);
        mViewDaily.intro.setOnClickListener(dailyOnClick);
        mViewDaily.recommendLayout.setOnClickListener(dailyOnClick);
        mViewDaily.likeLayout.setOnClickListener(dailyOnClick);
        mViewDaily.commentLayout.setOnClickListener(dailyOnClick);
        mViewDaily.imagePics.setOnClickListener(dailyOnClick);
        mViewDaily.teamNameLayout.setOnClickListener(dailyOnClick);
    }

    private void setPost(ViewPost mViewPost, Timeline mItem, int postion) {
        setOrgin(mViewPost, mItem);
        setBottom(mViewPost, mItem);
        setBottom(mViewPost, mItem);
        mViewPost.teamName.setText(StringUtil.htmlDecoder(mItem.getGname()));
        if (!TextUtils.isEmpty(mItem.getContentAddress())) {
            String[] addressList = mItem.getContentAddress().split(" ");
            if (addressList.length == 0) {
                mViewPost.imagePics.setVisibility(View.GONE);
            } else {
                mViewPost.imagePics.setVisibility(View.VISIBLE);
                for (int i = 0; i < mViewPost.content.length; i++) {
                    if (i < addressList.length) {
                        mViewPost.content[i].setVisibility(View.VISIBLE);
                        ImageLoader.getInstance().displayImage(addressList[i], mViewPost.content[i], ImageOptions.options)
                        ;
                    } else {
                        mViewPost.content[i].setVisibility(View.INVISIBLE);
                    }
                }
            }
        } else {
            mViewPost.imagePics.setVisibility(View.GONE);
        }
        String pic_num = mItem.getPic_num();
        if (!TextUtils.isEmpty(pic_num)) {
            if (Integer.parseInt(pic_num) > 3) {
                mViewPost.pagenum.setVisibility(View.VISIBLE);
            } else {
                mViewPost.pagenum.setVisibility(View.GONE);
            }
        } else {
            mViewPost.pagenum.setVisibility(View.GONE);
        }
        if (TextUtils.isEmpty(mItem.getIntro())) {
            mViewPost.intro.setVisibility(View.GONE);
        } else {
            mViewPost.intro.setVisibility(View.VISIBLE);
            mViewPost.intro.setText(mItem.getIntro());
        }
        mViewPost.tags.setVisibility(View.GONE);
        OnClick dailyOnClick = new OnClick(postion);
        mViewPost.head.setOnClickListener(dailyOnClick);
        mViewPost.name.setOnClickListener(dailyOnClick);
        mViewPost.intro.setOnClickListener(dailyOnClick);
        mViewPost.recommendLayout.setOnClickListener(dailyOnClick);
        mViewPost.likeLayout.setOnClickListener(dailyOnClick);
        mViewPost.commentLayout.setOnClickListener(dailyOnClick);
        mViewPost.imagePics.setOnClickListener(dailyOnClick);
        mViewPost.teamNameLayout.setOnClickListener(dailyOnClick);
    }

    private void setWriter(ViewWriter mViewWriter, Timeline mItem, int postion) {
        ImageLoader.getInstance().displayImage(mItem.getContentAddress(), mViewWriter.content, ImageOptions.options, null, null, true);
        setOrgin(mViewWriter, mItem);
        setBottom(mViewWriter, mItem);
        processTagData(mViewWriter, mItem, 0);
        mViewWriter.tvWriterDesc.setText(Html.fromHtml(mItem.getTitle()));
        if (!TextUtils.isEmpty(mItem.getIntro())) {
            mViewWriter.intro.setVisibility(View.VISIBLE);
            mViewWriter.intro.setText(Html.fromHtml(mItem.getIntro()).toString().trim());
        } else {
            mViewWriter.intro.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getSummary())) {
            mViewWriter.summery.setText(Html.fromHtml(mItem.getSummary()).toString().trim().replaceAll("(\\n)+", "\n"));
            mViewWriter.ellipsis.setText("......");
        }
        if ("true".equals(mItem.getPost_in_set())) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mViewWriter.ivSeries.setImageDrawable(mContext.getResources().getDrawable(R.drawable.timeline_serise, mContext.getTheme()));
            } else {
                mViewWriter.ivSeries.setImageDrawable(mContext.getResources().getDrawable(R.drawable.timeline_serise));
            }
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mViewWriter.ivSeries.setImageDrawable(mContext.getResources().getDrawable(R.drawable.timeline_single_write, mContext.getTheme()));
            } else {
                mViewWriter.ivSeries.setImageDrawable(mContext.getResources().getDrawable(R.drawable.timeline_single_write));
            }
        }
        OnClick writerOnClick = new OnClick(postion);
        mViewWriter.likeLayout.setOnClickListener(writerOnClick);
        mViewWriter.head.setOnClickListener(writerOnClick);
        mViewWriter.recommendLayout.setOnClickListener(writerOnClick);
        mViewWriter.content.setOnClickListener(writerOnClick);
        mViewWriter.commentLayout.setOnClickListener(writerOnClick);
        mViewWriter.name.setOnClickListener(writerOnClick);
        mViewWriter.intro.setOnClickListener(writerOnClick);
    }


    private void setGroup(ViewGroupTeam mViewGroupTeam, Timeline mItem, int position) {
        setOrgin(mViewGroupTeam, mItem);
        mViewGroupTeam.tvGroupTeamTitle.setText(Html.fromHtml(mItem.getGroupTitle()));
        if ("0".equals(mItem.getPost_num())) {
            mViewGroupTeam.tvGroupTeamJoin.setText(mContext.getString(R.string.post_message));
        } else {
            mViewGroupTeam.tvGroupTeamJoin.setText(String.format(mContext.getString(R.string.join_talk_card), mItem.getPost_num()));
        }
        if (TextUtils.isEmpty(mItem.getContentAddress())) {
            mViewGroupTeam.ivGroupCover.setVisibility(View.GONE);
        } else {
            mViewGroupTeam.ivGroupCover.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(mItem.getContentAddress(), mViewGroupTeam.ivGroupCover, ImageOptions.options);
        }
        if (TextUtils.isEmpty(mItem.getIntro())) {
            mViewGroupTeam.tvGroupTeamDesc.setVisibility(View.GONE);
        } else {
            mViewGroupTeam.tvGroupTeamDesc.setVisibility(View.VISIBLE);
            mViewGroupTeam.tvGroupTeamDesc.setText(Html.fromHtml(mItem.getIntro()));
        }
        OnClick viewGroupTeamOnClick = new OnClick(position);
        mViewGroupTeam.head.setOnClickListener(viewGroupTeamOnClick);
        mViewGroupTeam.name.setOnClickListener(viewGroupTeamOnClick);
        mViewGroupTeam.viewBody.setOnClickListener(viewGroupTeamOnClick);
    }

    private void setArticle(ViewArticle mViewArticle, Timeline mItem, int position) {
        ImageLoader.getInstance().displayImage(mItem.getContentAddress(), mViewArticle.content, ImageOptions.optionsTimeline, null, null, true);
        mViewArticle.pageNum.setVisibility(View.GONE);
        if (!TextUtils.isEmpty(mItem.getTitle())) {
            mViewArticle.title.setVisibility(View.VISIBLE);
            mViewArticle.title.setText(Html.fromHtml(mItem.getTitle()));
        } else {
            mViewArticle.title.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getSummary())) {
            mViewArticle.summary.setVisibility(View.VISIBLE);
            mViewArticle.summary.setText(Html.fromHtml(mItem.getSummary()));
        } else {
            mViewArticle.summary.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(mItem.getOUName())) {
            mViewArticle.author.setVisibility(View.VISIBLE);
            mViewArticle.author.setText(mItem.getOUName());
        } else {
            mViewArticle.author.setVisibility(View.GONE);
        }
        setOrgin(mViewArticle, mItem);
        setBottom(mViewArticle, mItem);
        processTagData(mViewArticle, mItem, 0);
        OnClick groundOnClick = new OnClick(position);
        mViewArticle.head.setOnClickListener(groundOnClick);
        mViewArticle.name.setOnClickListener(groundOnClick);
        mViewArticle.recommendLayout.setOnClickListener(groundOnClick);
        mViewArticle.content.setOnClickListener(groundOnClick);
        mViewArticle.likeLayout.setOnClickListener(groundOnClick);
        mViewArticle.commentLayout.setOnClickListener(groundOnClick);
        ((View) (mViewArticle.title.getParent())).setOnClickListener(groundOnClick);
    }

    private void processTagData(BaseView baseView, final Timeline mItem, final int from) {
        if (mItem.getTags() != null && mItem.getTags().size() > 0) {
            baseView.tags.setVisibility(View.VISIBLE);
        } else {
            baseView.tags.setVisibility(View.GONE);
        }
        if (mItem.getTags() != null && mItem.getTags().size() > 0) {
            baseView.tags.setTlist(mItem.getTags());
            baseView.tags.setTagViewClick(new TagView.OnTagClickListener() {
                @Override
                public void onClick(TagDetail t) {
                    if (!TextUtils.isEmpty(t.getWork())) {
                        if (!TextUtils.isEmpty(t.getWid())) {
                            Intent intent = new Intent(mContext, CircleSmoothActivity.class);
                            intent.putExtra(gotoUtil.INTENT_VALUE_ONE, t.getWork());
                            intent.putExtra(gotoUtil.INTENT_VALUE_TWO, t.getWid());
                            intent.putExtra("from", from);
                            mContext.startActivity(intent);
                        }
                    } else if (!TextUtils.isEmpty(t.getEvent_id())) {
                        gotoUtil.gotoAct(mContext, EventDetailActivity.class, t.getEvent_id());
                    } else {
                        Intent intent = new Intent(mContext, CircleTagSmoothActivity.class);
                        intent.putExtra(gotoUtil.INTENT_VALUE_ONE, t.getTag_name());
                        intent.putExtra("type", "tag");
                        intent.putExtra("from", from);
                        mContext.startActivity(intent);
                    }
                }
            });
        }
    }


    private void renderGridGroup(int position, ViewSmallGroup viewItem, Timeline item) {
        if (!TextUtils.isEmpty(item.getCover())) {
            viewItem.ivItems.setVisibility(View.VISIBLE);
            viewItem.tvItems.setVisibility(View.GONE);
            ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        } else {
            viewItem.ivItems.setVisibility(View.INVISIBLE);
            viewItem.tvItems.setVisibility(View.VISIBLE);
            setGridBottomPlain(item.getPlain(), viewItem.tvItems);
        }
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.writeItemViews.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
    }

    private void renderGridWrite(int position, ViewSmallWrite viewItem, Timeline item) {
        ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        viewItem.tvWriteTitles.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(item.getTitle())) {
            viewItem.tvWriteTitles.setText(Html.fromHtml(item.getTitle()));
        }
        String tagString = getTagString(item);
        if (TextUtils.isEmpty(tagString))
            viewItem.tvWriteTags.setVisibility(View.GONE);
        else {
            viewItem.tvWriteTags.setVisibility(View.VISIBLE);
            viewItem.tvWriteTags.setText(tagString);
        }
        setGridBottomPlain(item.getIntro(), viewItem.plain);
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.ivItems.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
    }

    private void renderGridVideo(int position, ViewSmallVideoDaily viewItem, Timeline item) {
        ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        setGridBottomPlain(item.getPlain(), viewItem.plain);
        try {
            String time = StringUtil.getTimeDuration((int) Double.parseDouble(item.getVideo_info().getDuration()));
            viewItem.image_count.setText(time);
            viewItem.image_count.setVisibility(View.GONE);
        } catch (Exception e) {
            viewItem.image_count.setVisibility(View.VISIBLE);
        }
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.writeItemViews.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
    }

    private void renderGridLongDaily(int position, ViewSmallLongDaily viewItem, Timeline item) {
        viewItem.item_label.setText(mContext.getString(R.string.larticle));
        if (!TextUtils.isEmpty(item.getTitle()))
            viewItem.tvWriteTitles.setText(item.getTitle());
        if (!TextUtils.isEmpty(item.getCover())) {
            viewItem.writeItemViews.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        } else {
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                viewItem.ivItems.setImageDrawable(mContext.getResources().getDrawable(R.drawable.larticle_cover, mContext.getTheme()));
            } else {
                viewItem.ivItems.setImageDrawable(mContext.getResources().getDrawable(R.drawable.larticle_cover));
            }
        }
        setGridBottomPlain(item.getPlain(), viewItem.plain);
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.writeItemViews.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
    }


    private void renderGridDaily(int position, RecyclerView.ViewHolder holder, Timeline item) {
        ViewSmallDaily viewItem = (ViewSmallDaily) holder;
        if (!TextUtils.isEmpty(item.getPic_num())) {
            if (Integer.parseInt(item.getPic_num()) > 1) {
                viewItem.image_count.setVisibility(View.VISIBLE);
            } else {
                viewItem.image_count.setVisibility(View.GONE);
            }
        }
        if (!TextUtils.isEmpty(item.getCover())) {
            viewItem.writeItemViews.setVisibility(View.VISIBLE);
            viewItem.daily_text.setVisibility(View.GONE);
            viewItem.plain.setVisibility(View.VISIBLE);
            setGridBottomPlain(item.getPlain(), viewItem.plain);
            ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        } else {
            viewItem.daily_text.setVisibility(View.VISIBLE);
            viewItem.plain.setVisibility(View.GONE);
            viewItem.writeItemViews.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(item.getPlain())) {
                viewItem.daily_text.setVisibility(View.VISIBLE);
                viewItem.daily_text.setText(Html.fromHtml(item.getPlain()));
            } else {
                viewItem.writeItemViews.setVisibility(View.VISIBLE);
                viewItem.ivItems.setVisibility(View.VISIBLE);
                viewItem.daily_text.setVisibility(View.GONE);
                if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
                    viewItem.ivItems.setImageDrawable(mContext.getResources().getDrawable(R.drawable.larticle_cover, mContext.getTheme()));
                } else {
                    viewItem.ivItems.setImageDrawable(mContext.getResources().getDrawable(R.drawable.larticle_cover));
                }
            }
        }
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.writeItemViews.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
        viewItem.daily_text.setOnClickListener(onclick);
    }

    private void renderGridMain(int position, RecyclerView.ViewHolder holder, Timeline item) {
        ViewSmallMain viewItem = (ViewSmallMain) holder;
        ImageLoader.getInstance().displayImage(item.getCover(), viewItem.ivItems, ImageOptions.options);
        if (!TextUtils.isEmpty(item.getPic_num())) {
            if (Integer.parseInt(item.getPic_num()) > 1) {
                viewItem.image_count.setVisibility(View.VISIBLE);
            } else {
                viewItem.image_count.setVisibility(View.GONE);
            }
        }
        setGridBottomPlain(item.getPlain(), viewItem.plain);
        setGridBottomData(item, viewItem);
        OnClick onclick = new OnClick(position);
        viewItem.ivItems.setOnClickListener(onclick);
        viewItem.plain.setOnClickListener(onclick);
        viewItem.name.setOnClickListener(onclick);
        viewItem.zan_line.setOnClickListener(onclick);
        viewItem.header.setOnClickListener(onclick);
    }

    private void setGridBottomPlain(String plainString, TextView plain) {
        if (!TextUtils.isEmpty(plainString)) {
            plain.setVisibility(View.VISIBLE);
            plain.setText(Html.fromHtml(plainString));
        } else {
            plain.setVisibility(View.GONE);
        }
    }

    private void setGridBottomData(Timeline item, GridCircleBaseItem viewItem) {
        if (!TextUtils.isEmpty(item.getUname())) {
            viewItem.name.setText(item.getUname());
        }
        if (!TextUtils.isEmpty(item.getAvatar())) {
            ImageLoader.getInstance().displayImage(item.getAvatar(), viewItem.header, ImageOptions.optionHead);
        }
        if (item.isHave_ding()) {
            viewItem.zan_pic.setImageResource(R.drawable.like_pink);
        } else {
            viewItem.zan_pic.setImageResource(R.drawable.like_grey);
        }
        if (item.getDing_num() != 0) {
            viewItem.zan_num.setText(String.valueOf(item.getDing_num()));
        } else {
            viewItem.zan_num.setText(mContext.getString(R.string.good));
        }
    }

    @NonNull
    private String getTagString(Timeline mItem) {
        StringBuffer sb = new StringBuffer();
        if (null != mItem && null != mItem.getPost_tags()) {
            for (String s : mItem.getPost_tags()) {
                sb.append(s);
                sb.append("/");
            }
            if (sb.length() > 0)
                sb.delete(sb.length() - 1, sb.length());
        }
        return sb.toString();
    }

    @Override
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        super.onViewAttachedToWindow(holder);
        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
        if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams && (holder.getLayoutPosition() <= 1 || holder.getLayoutPosition() == getItemCount() - 1 || holder.getItemViewType() == TimelineCardType.EMPTY_CARD)) {
            StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
            p.setFullSpan(true);
        }
    }

    private class BlankHolder extends RecyclerView.ViewHolder {

        View blank;

        public BlankHolder(View itemView) {
            super(itemView);
            blank = itemView.findViewById(R.id.blank);
        }
    }

    private class BottomHolder extends RecyclerView.ViewHolder {

        RelativeLayout blank;
        RelativeLayout empty;
        LinearLayout loading;

        public BottomHolder(View itemView) {
            super(itemView);
            blank = (RelativeLayout) itemView.findViewById(R.id.smooth_bottom);
            empty = (RelativeLayout) itemView.findViewById(R.id.event_empty);
            loading = (LinearLayout) itemView.findViewById(R.id.progressbar_loading_layout);
        }
    }

    @Override
    public int getItemCount() {
        if (tlist.isEmpty()) {
            if (clist == null) {
                return 3;
            } else {
                return clist.size() + 3;
            }
        } else {
            return tlist.size() + 3;
        }
    }

    class OnClick implements View.OnClickListener {

        int position;
        Timeline mItem;
        int timelineType;

        public OnClick(int position) {
            this.position = position;
            if (tlist.isEmpty()) {
                this.mItem = clist.get(position - 2);
            } else {
                this.mItem = tlist.get(position - 2);
            }
            timelineType = TimelineFactory.whichType(mItem);
        }

        @Override
        public void onClick(final View v) {
            switch (v.getId()) {
                case R.id.group_view_container:
                case R.id.daily_teamname_rly:
                    gotoUtil.gotoAct(mContext, NewTeamDetailActivity.class, mItem.getGid(), mItem.getGname());
                    break;
                case R.id.ground_name_tv:
                case R.id.ground_head_img:
                    gotoUtil.gotoAct(mContext, SmoothPersonActivity.class, mItem.getUid());
                    break;
                case R.id.ground_content_img:
                case R.id.ground_intro_tv:
                case R.id.ground_intro_content:
                case R.id.ground_content_rly:
                case R.id.article_click:
                case R.id.daily_teamname_tv:
                    switch (timelineType) {
                        case TimelineFactory.TIMELINE_TYPE_COSER:
                            DetailDataHelper.gotoCosDetail(mContext, mItem.getRp_id(), mItem.getCp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_ILLUST:
                            DetailDataHelper.gotoDrawerDetail(mContext, mItem.getRp_id(), mItem.getDp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_WRITER:
                            DetailDataHelper.gotoWriterDetail(mContext, mItem.getRp_id(), mItem.getWp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GOODS:
                            gotoUtil.gotoAct(mContext, GoodsDetailActivity.class, mItem.getZg_id());
                            break;
                        case TimelineFactory.TIMELINE_TYPE_DAILY:
                            DetailDataHelper.gotoDailyDetail(mContext, mItem.getUd_id(), false);
                            break;
                    }
                    break;
                case R.id.daily_intro_tv:
                case R.id.rl_daily_pics:
                    switch (timelineType) {
                        case TimelineFactory.TIMELINE_TYPE_DAILY:
                            DetailDataHelper.gotoDailyDetail(mContext, mItem.getUd_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GROUP:
                            DetailDataHelper.gotoGroupDetail(mContext, mItem.getGid(), mItem.getPost_id(), false);
                            break;
                    }
                    break;
                case R.id.ground_like_rly:
                    if (isAnimation_runing) break;
                    TimelineLikeHelper.doLikeAll(mContext, mQueue, mItem, new TimelineLikeHelper.TimelineSuccess() {
                        @Override
                        public void onTimelineSuccess() {
                            if (!Boolean.parseBoolean(mItem.getHaveDing())) {
                                mItem.setHaveDing(String.valueOf(true));
                                mItem.setLikeNum(StringUtil.getString(
                                        StringUtil.getInt(mItem.getLikeNum()) + 1));
                            } else {
                                mItem.setHaveDing(String.valueOf(false));
                                mItem.setLikeNum(StringUtil.getString(
                                        StringUtil.getInt(mItem.getLikeNum()) - 1));
                            }
                            updateLike(v, mItem);
                        }
                    });
                    break;
                case R.id.ground_comment_rly:
                    switch (timelineType) {
                        case TimelineFactory.TIMELINE_TYPE_COSER:
                            DetailDataHelper.gotoCosDetail(mContext, mItem.getRp_id(), mItem.getCp_id(), true);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_ILLUST:
                            DetailDataHelper.gotoDrawerDetail(mContext, mItem.getRp_id(), mItem.getDp_id(), true);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_DAILY:
                            DetailDataHelper.gotoDailyDetail(mContext, mItem.getUd_id(), true);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GROUP:
                            DetailDataHelper.gotoGroupDetail(mContext, mItem.getGid(), mItem.getPost_id(), true);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_WRITER:
                            DetailDataHelper.gotoWriterDetail(mContext, mItem.getRp_id(), mItem.getWp_id(), true);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_ASK:
                            gotoUtil.gotoAct(mContext, AskActivity.class, mItem.getOuid(), mItem.getOUName());
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GOODS:
                            gotoUtil.gotoAct(mContext, GoodsDetailActivity.class, mItem.getZg_id());
                            break;
                    }
                    break;
                case R.id.ground_recommend_rly:
                    TimelineLikeHelper.doRecommendAll(mContext, mQueue, mItem, new TimelineLikeHelper.TimelineSuccess() {
                        @Override
                        public void onTimelineSuccess() {
                            mItem.setHaveRecommend(String.valueOf(!Boolean.valueOf(mItem.getHaveRecommend())));
                            updatePriase(v, mItem);
                        }
                    });
                    break;
                case R.id.write_cover:
                    DetailDataHelper.gotoWriterDetail(mContext, mItem.getRp_id(), mItem.getWp_id(), false);
                    break;
                case R.id.write_item_one:
                case R.id.plain:
                case R.id.daily_text:
                case R.id.siv_item_one:
                    switch (timelineType) {
                        case TimelineFactory.TIMELINE_TYPE_COSER:
                            DetailDataHelper.gotoCosDetail(mContext, mItem.getRp_id(), mItem.getCp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_ILLUST:
                            DetailDataHelper.gotoDrawerDetail(mContext, mItem.getRp_id(), mItem.getDp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_DAILY:
                            DetailDataHelper.gotoDailyDetail(mContext, mItem.getUd_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_WRITER:
                            DetailDataHelper.gotoWriterDetail(mContext, mItem.getRp_id(), mItem.getWp_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GROUP:
                            DetailDataHelper.gotoGroupDetail(mContext, mItem.getGid(), mItem.getPost_id(), false);
                            break;
                        case TimelineFactory.TIMELINE_TYPE_GROUP_TEAM:
                            gotoUtil.gotoAct(mContext, NewTeamDetailActivity.class, mItem.getGid());
                            break;

                    }
                    break;
                case R.id.user_head_one:
                case R.id.uname_one:
                    gotoUtil.gotoAct(mContext, SmoothPersonActivity.class, mItem.getUid());
                    break;
                case R.id.zan_line_one:
                    TimelineLikeHelper.doLikeAllForCircle(mContext, VolleyQueue.getRquest(mContext), mItem, new TimelineLikeHelper.TimelineSuccess() {
                        @Override
                        public void onTimelineSuccess() {
                            if (!mItem.isHave_ding()) {
                                mItem.setHave_ding(true);
                                mItem.setDing_num(mItem.getDing_num() + 1);
                                mItem.setLikeNum(String.valueOf(mItem.getDing_num()));
                            } else {
                                mItem.setHave_ding(false);
                                mItem.setDing_num(mItem.getDing_num() - 1);
                                mItem.setLikeNum(String.valueOf(mItem.getDing_num()));
                            }
                            updateLikePinester(v, mItem);
                        }
                    });

                    break;
                default:
                    break;
            }
        }

    }

    private void updateLike(View view, final Timeline mItem) {
        final ImageView likeNumImg = (ImageView) view.findViewById(R.id.ground_like_img);
        final TextView likeNum = (TextView) view.findViewById(R.id.ground_likenumber_tv);
        if (StringUtil.getHaveDingBoolean(mItem)) {
            isAnimation_runing = true;
            likeNumImg.setScaleY(2f);
            likeNumImg.setScaleX(2f);
            likeNumImg.setImageResource(R.drawable.frame_praise);
            AnimationDrawable drawable = (AnimationDrawable) likeNumImg.getDrawable();
            drawable.start();
            likeNumImg.postDelayed(new Runnable() {
                @Override
                public void run() {
                    likeNumImg.setScaleY(1f);
                    likeNumImg.setScaleX(1f);
                    likeNumImg.setImageResource(R.drawable.like_pink);
                    likeNum.setText(mItem.getLikeNum());
                    isAnimation_runing = false;
                }
            }, 24 * 20);
        } else {
            likeNumImg.setImageResource(R.drawable.like_grey);
            likeNum.setText(mItem.getLikeNum());
            if (mItem.getLikeNum().equals("0")) {
                likeNum.setText(mContext.getString(R.string.good));
            }
        }
    }

    private void updatePriase(View view, Timeline mItem) {
        TextView recommend = (TextView) view.findViewById(R.id.ground_recommend_tv);
        if (StringUtil.notNullEqual(mItem.getHaveRecommend(), "true")) {
            recommend.setText(mContext.getString(R.string.all_recommended));
        } else {
            recommend.setText(mContext.getString(R.string.all_recommend));
        }
    }

    private void updateLikePinester(View view, final Timeline mItem) {
        final ImageView likeNumImg = (ImageView) view.findViewById(R.id.zan_label_one);
        final TextView likeNum = (TextView) view.findViewById(R.id.zan_count_one);
        if (mItem.isHave_ding()) {
            isAnimation_runing = true;
            likeNumImg.setScaleY(2f);
            likeNumImg.setScaleX(2f);
            likeNumImg.setImageResource(R.drawable.frame_praise);
            AnimationDrawable drawable = (AnimationDrawable) likeNumImg.getDrawable();
            drawable.start();
            likeNumImg.postDelayed(new Runnable() {
                @Override
                public void run() {
                    likeNumImg.setScaleY(1f);
                    likeNumImg.setScaleX(1f);
                    likeNumImg.setImageResource(R.drawable.like_pink);
                    likeNum.setText(String.valueOf(mItem.getDing_num()));
                    isAnimation_runing = false;
                }
            }, 24 * 20);
        } else {
            likeNumImg.setImageResource(R.drawable.like_grey);
            likeNum.setText(mItem.getLikeNum());
            if (mItem.getDing_num() == 0) {
                likeNum.setText(mContext.getString(R.string.good));
            }
        }
    }

    public void setLoading(boolean loading) {
        this.loading = loading;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public void setMax(int max) {
        this.max = max;
    }

}
